//
//  AppConfig.swift
//  YaoXinCalculator
//
//  Created by Li Dong on 2023/6/1.
//

import UIKit

class AppConfig: NSObject {

    static var finishGuide: Bool {
        get {
            return UserDefaults.standard.bool(forKey: "finishGuide")
        }
        set {
            UserDefaults.standard.set(true, forKey: "finishGuide")
            UserDefaults.standard.synchronize()
        }
    }
    
    //协议
    static let SERVICE_URL = NSLocalizedString("https://bx9nsbdd0d9.feishu.cn/docx/Nj5jdPW4loynJbx4tbLcHsTtnIb", comment: "")
    static let PRIVACY_URL = NSLocalizedString("https://bx9nsbdd0d9.feishu.cn/docx/TtaUdwh34osccvxDA4mcLwCTnUg", comment: "")
     
    static let H5_URL = NSLocalizedString("http://qinghu2.cvbrtte.shop/h5/qinghu/word.html?userId=", comment: "") + getUserId()
    

    
    static var isBuy: Bool {
        set {
            UserDefaults.standard.set(newValue, forKey: "isBuy")
            UserDefaults.standard.synchronize()
        }
        get {
            return UserDefaults.standard.bool(forKey: "isBuy")
        }
    }
    
    
    static let isEnglishEnv = NSLocalizedString("中文版", comment: "") == "英文版"
    
    private static var userId: String {
        get {
            if let tt = UserDefaults.standard.string(forKey: "userId") {
                return tt
            }
            return ""
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "userId")
            UserDefaults.standard.synchronize()
        }
    }
    
    static func getUserId() -> String {
        if !userId.isEmpty {
            return userId
        }
        userId = "user\(timestamp())\(randomNumber())"
        return userId
    }
    
    
    static func randomNumber() -> Int {
        //m~n之间的随机数
        //x = arc4random()%(n-m+1)+m
        return Int(arc4random()%(1000) + 1)
    }
    
    static func timestamp() -> Int {
        return Int(Date().timeIntervalSince1970)
    }
    
}
